package cn.achao.csr.chat.controller;

import cn.achao.csr.api.model.req.MemberReq;
import cn.achao.csr.api.model.resp.ChatMemberResp;
import cn.achao.csr.api.model.resp.MemberResp;
import cn.achao.csr.base.resp.CursorPageBaseResp;
import cn.achao.csr.base.resp.R;
import cn.achao.csr.chat.service.ChatRoomService;
import cn.achao.csr.security.utils.SecurityUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @Author: achao
 **/
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/room")
public class ChatRoomController {

    private final ChatRoomService roomService;

    /**
     * 群组详情
     * @param roomId
     * @return
     */
    @GetMapping("/detail")
    public R<MemberResp> roomDetail(Long roomId) {
        Long userId = SecurityUtils.getUserId();
        MemberResp resp = roomService.roomDetail(roomId, userId);
        return R.ok(resp);
    }

    /**
     * 群成员列表
     * @param req
     * @return
     */
    @GetMapping("/group/member/page")
    public R<CursorPageBaseResp<ChatMemberResp>> getMemberPage(@Valid MemberReq req) {
        return R.ok(roomService.getMemberPage(req));
    }
}
